package com.immediatus.engine.collision;

public class BaseCollisionChecker{

    public static boolean checkAxisAlignedRectangleCollision(final float pLeftA, final float pTopA, final float pRightA, final float pBottomA, final float pLeftB, final float pTopB, final float pRightB, final float pBottomB){
        return (pLeftA < pRightB &&
                pLeftB < pRightA &&
                pTopA < pBottomB &&
                pTopB < pBottomA);
    }

    public static int relativeCCW(final float pX1, final float pY1, float pX2, float pY2, float pPX, float pPY){
        pX2 -= pX1;
        pY2 -= pY1;
        pPX -= pX1;
        pPY -= pY1;
        float ccw = pPX * pY2 - pPY * pX2;
        if (ccw == 0.0f){
            ccw = pPX * pX2 + pPY * pY2;
            if (ccw > 0.0f){
                pPX -= pX2;
                pPY -= pY2;
                ccw = pPX * pX2 + pPY * pY2;
                if (ccw < 0.0f){
                    ccw = 0.0f;
                }
            }
        }
        return (ccw < 0.0f) ? -1 : ((ccw > 0.0f) ? 1 : 0);
    }
}
